<?php
$accountService = new AccountService();
$languageService = new LanguageServices();
$currencyService = new CurrencyServices();
if(isset($_GET['opt']))
{
	$opt = $_GET['opt'];
	$moduleID = $moduleService->getModuleIDByFuncAndOpt($context, $result, $func, $opt);
	$permit = $permitService->checkPermition($context, $result, $_SESSION['user']['type'], $moduleID);

	if($opt == "permit" && $permit ==true)
	{
		$permitService = new PermitService();
		$permitModuleArr = $permitService->getPermit($context, $result);
		$smarty->assign("permitModuleArr",$permitModuleArr);
		$smarty->display($templateDir . "/temp1/userPermit.tpl");
	}
	if($opt == "email" && $permit ==true)
	{
		$host = Tool::decode($smtp['host'], "sTunnInVietnAm@2012#");
		$port = Tool::decode($smtp['port'], "sTunnInVietnAm@2012#");
		$user = Tool::decode($smtp['user'], "sTunnInVietnAm@2012#");
		$pass = Tool::decode($smtp['pass'], "sTunnInVietnAm@2012#");
		$emailService = new EmailService($host, $port, $user, $pass);
		$start = $p->findStart($configPage['limit']);
		$count = $emailService->countAllEmail($context, $result);
		$pages = $p->findPages($count,$configPage['limit']);
		$page_list = $p->pagesList($_GET['page'],$pages,$configPage);
		$emailList = $emailService->findAllEmailByRange($context, $result, $start, $configPage['limit']);
		$total = "Page ".$_GET['page']." in ".$pages. " Pages";
		$smarty->assign('total', $total);
		$smarty->assign('page_list', $page_list);
		$smarty->assign("emailList", $emailList);
		$smarty->display($templateDir . "/temp1/listEmail.tpl");
	}
	if($opt == "editEmail" && $permit ==true)
	{
		if(isset($_GET['id']) && is_numeric($_GET['id']))
		{
			$countryList = $countryService->findAllCountry($context, $result);
			$host = Tool::decode($smtp['host'], "sTunnInVietnAm@2012#");
			$port = Tool::decode($smtp['port'], "sTunnInVietnAm@2012#");
			$user = Tool::decode($smtp['user'], "sTunnInVietnAm@2012#");
			$pass = Tool::decode($smtp['pass'], "sTunnInVietnAm@2012#");
			$emailService = new EmailService($host, $port, $user, $pass);
			$email = $emailService->findEmailByOid($context, $result, $_GET['id']);
			$smarty->assign('email', $email);
			$smarty->assign('countryList', $countryList);
			$smarty->display($templateDir . "/temp1/editEmail.tpl");
		}
	}
	if($opt == "addEmail" && $permit ==true)
	{
		$countryList = $countryService->findAllCountry($context, $result);
		$smarty->assign('countryList', $countryList);
		$smarty->display($templateDir . "/temp1/addEmail.tpl");
	}
	if($opt == "list" && $permit ==true)
	{
			
	}

	if($opt == "config" && $permit ==true)
	{
		$c = new Config();
		$root =& $c->parseConfig(dirname(__FILE__).DIRECTORY_SEPARATOR.'../../_config/setting/setting.ini', 'inifile');
		$settingsSection =& $root->getItem("section", "BArt-system");
		$host =& $settingsSection->getItem("directive", "BArt_system_MYSQL_HOST");
		$dbName =& $settingsSection->getItem("directive", "BArt_system_MYSQL_NAME");
		$user =& $settingsSection->getItem("directive", "BArt_system_MYSQL_USER");
		$pass =& $settingsSection->getItem("directive", "BArt_system_MYSQL_PASS");
			
		$host = $host->getContent();
		$dbName = $dbName->getContent();
		$user = $user->getContent();
		$pass = $pass->getContent();
			
		$smarty->assign('host', Tool::decode($host, "sTunnInVietnAm@2012#"));
		$smarty->assign('dbName', Tool::decode($dbName, "sTunnInVietnAm@2012#"));
		$smarty->assign('user', Tool::decode($user, "sTunnInVietnAm@2012#"));
		$smarty->assign('pass', Tool::decode($pass, "sTunnInVietnAm@2012#"));
			
		$smarty->assign('limit', $configPage['limit']);
		$smarty->assign('curPage', $configPage["tag"]["curPage"]);
		$smarty->assign('firstLastPage', $configPage["tag"]["firstLastPage"]);
		$smarty->assign('pageNum', $configPage["tag"]["pageNum"]);
			
		$smarty->assign('websiteURL', $glb["websiteURL"]);
		$smarty->assign('settingDir', $glb["settingDir"]);
		$smarty->assign('layoutDir', $glb["layoutDir"]);
		$smarty->assign('controllerDir', $glb["controllerDir"]);
		$smarty->assign('contactEmail', $glb["contactEmail"]);
			
		$smarty->assign('hostEmail', Tool::decode($smtp["host"],"sTunnInVietnAm@2012#"));
		$smarty->assign('port', Tool::decode($smtp["port"],"sTunnInVietnAm@2012#"));
		$smarty->assign('userHost', Tool::decode($smtp["user"],"sTunnInVietnAm@2012#"));
		$smarty->assign('passHost', Tool::decode($smtp["pass"],"sTunnInVietnAm@2012#"));
		
		$smarty->assign('num', $num["orderNumber"]);
		$smarty->assign('numInvoice', $num["invoiceNumber"]);

		$smarty->display($templateDir . "/temp1/config.tpl");
	}

	if($opt == "companyInfo" && $permit ==true)
	{
		$countryList = $countryService->findAllCountry($context, $result);
		$account = $accountService->getAccountByOid($context,$result,1);
		$languageList = $languageService->findAllLanguage($context, $result);
		$currencyList = $currencyService->findAllCurrency($context, $result);
		$smarty->assign('currencyList',$currencyList);
		$smarty->assign('languageList', $languageList);
		$smarty->assign('countryList', $countryList);
		$smarty->assign('account', $account);
		$smarty->display($templateDir . "/temp1/viewCompany.tpl");
	}
}
?>